package com.china08.yxyapi.api.manage.tec.teaching.live.lessonManage;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.api.manage.tec.teaching.live.myClassSchedule.MyClassScheduleController;
import com.china08.yxyapi.model.YxyApiReqModel;

import io.swagger.annotations.ApiOperation;

/**
 * 我的教学-直播课-教师-直播课目录查询
 * @author 赵亚辉
 *
 */
@CrossOrigin
@RestController
public class LiveCatalogController extends YxyApiBaseController{
	
	private static final Logger logger=Logger.getLogger(MyClassScheduleController.class);
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@ApiOperation(value = "直播课目录查询")
    @RequestMapping(value = "/api_yw/manage/tec/teaching/live/liveCatalog/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel find(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
		
		RespModel respModel=new RespModel();
		
		String schoolId = getProfile(request, response).getSchoolId();
		
		String dataSQL="select id,name from yxy_live.yxy_live_catalog where 1=1";
		String pid = reqModel.pid;
		if(StringUtils.isEmpty(pid)){
			dataSQL+=" and level=1";
		}else{
			dataSQL+=" and pid='"+pid+"'";
		}
		Integer operatestatus=reqModel.operatestatus;
		String eduOfficeId=reqModel.eduOfficeId;
		if(operatestatus==1){
			dataSQL+=" and school_id='"+schoolId+"'";
		}else if(operatestatus==2){
			dataSQL+=" and school_id='"+eduOfficeId+"'";
		}
		
		dataSQL+=" order by order_num";
		System.err.println("dataSQL:"+dataSQL);
		List<Map<String, Object>> mapList = jdbcTemplate.queryForList(dataSQL);
		
		respModel.liveCatalogList=mapList;
		
		return respModel;
	}
	
	protected static class ReqModel extends YxyApiReqModel{
		
		public String pid;
		// 1：学校查询；2：教育局查询
		public Integer operatestatus;
		// 教育局id
		public String eduOfficeId;
		
		@Override
        public void autoCheck() {
            Assert.notNull(operatestatus==null, "请填写查询方式");
            if(operatestatus==2){
            	Assert.notNull(StringUtils.defaultIfBlank(eduOfficeId, null), "请填写教育局id");
            }
        }
	}
	
	protected static class RespModel {
		
		public List<Map<String, Object>> liveCatalogList;

	}
	
}
